package com.guowen.myaccount.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.guowen.myaccount.MainActivity;
import com.guowen.myaccount.R;
import com.guowen.myaccount.db.AccountBean;
import com.guowen.myaccount.db.MenuBean;
import com.guowen.myaccount.utils.MenuDialog;

import java.util.List;

public class MenuAdapter extends BaseAdapter {

    private Context context;
    private List<MenuBean> mDatas;
    private LayoutInflater inflater;
    public int selectPos = 0; //默认选中的位置


    public MenuAdapter(Context context, List<MenuBean> mDatas){
        this.context = context;
        this.mDatas = mDatas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_menu_lv,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        MenuBean bean = mDatas.get(position);
        holder.menuTv.setText(bean.getMenuName());

        if (selectPos == position && bean.getKind() == 0){
            holder.menuIv.setImageResource(bean.getsImageId());
            holder.menuTv.setTextColor(Color.rgb(18,150,219));

        }else {
            holder.menuIv.setImageResource(bean.getImageId());
        }
        return convertView;
    }

    class ViewHolder{

        private ImageView menuIv;
        private TextView menuTv;

        public ViewHolder(View view) {
            menuIv = view.findViewById(R.id.item_menu_lv_iv);
            menuTv = view.findViewById(R.id.item_menu_lv_tv);
        }
    }
}
